package com.qipay.msg.impl;

import com.qipay.baas.model.Message;
import com.qipay.mapper.MessageMapper;
import com.qipay.msg.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    MessageMapper messageMapper;

    @Override
    @Transactional
    public int insert(Message msg) {
        return messageMapper.insert(msg);
    }

    @Override
    public List<Message> selectUnReadByUid(int uid) {
        return messageMapper.selectByReceiveIdUnread(uid);
    }

    @Override
    public List<Message> selectPageByUid(int uid, int p, int pz) {
        p = p <= 0 ? 1 : p;
        pz = pz <= 0 ? 10 : pz;
        return messageMapper.selectByReceiveId(uid, (p - 1) * pz, pz);
    }

    @Override
    public long countByReceiveId(int uid) {
        return messageMapper.countByReceiveId(uid);
    }

    @Override
    @Transactional
    public int updateReadedStatusByUid(int uid) {
        return messageMapper.updateStatusByReceiveId(uid);
    }
}
